package com.topsoft.micro.web;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


/**
 * 退出登录
 * @author Administrator
 *
 */
@Controller
public class LogoutController {
	
    
	@Autowired
	ConsumerTokenServices tokenServices;

    @RequestMapping("/oauth/exit")
    public void exit(HttpServletRequest request, HttpServletResponse response,Authentication authentication) {
    	
    	if(null==authentication) {
    		return;
    	}
    	//当前线程登出, 必须(否则客户端登出,服务端重新建立)
        new SecurityContextLogoutHandler().logout(request, null, null);
        
        try {
            response.sendRedirect(request.getHeader("referer"));
        } catch (IOException e) {
            e.printStackTrace();
        }
       
    }
    

}